package cn.zucc.edu.handyzucc.service.impl;

import cn.zucc.edu.handyzucc.dao.EventDao;
import cn.zucc.edu.handyzucc.entity.Event;
import cn.zucc.edu.handyzucc.entity.EventReg;
import cn.zucc.edu.handyzucc.entity.EventRegExtend;
import cn.zucc.edu.handyzucc.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EventServiceImpl implements EventService {
    @Autowired
    private EventDao eventDao;

    @Override
    public List<Event> getAllEvents() {
        return eventDao.getAllEvents();
    }

    @Override
    public Event getEventDetailById(Integer event_id) {
        return eventDao.getEventDetailById(event_id);
    }

    @Override
    public boolean eventReg(Integer eventreg_event, Integer eventreg_user) {
        int effectedNum = eventDao.eventReg(new EventReg(eventreg_event, eventreg_user));
        if (effectedNum == 1)
            return true;
        else return false;
    }

    @Override
    public boolean eventAlreadyReg(Integer eventreg_event, Integer eventreg_user) {
        EventReg event = eventDao.eventAlreadyReg(eventreg_event, eventreg_user);
        if (event!=null || event.getEventreg_id()>0)
            return true;
        else return false;
    }

    @Override
    public boolean addEvent(Event event) {
        return eventDao.addEvent(event)==1;
    }

    @Override
    public boolean deleteEvent(Integer event_id) {
        return eventDao.deleteEvent(event_id)==1;
    }

    @Override
    public boolean updateEvent(Event event) {
        return eventDao.updateEvent(event) == 1;
    }

    @Override
    public List<EventRegExtend> getEventReg(Integer event_id) {
        return eventDao.getEventReg(event_id);
    }
}
